<template>
  <div class="container-log">
    <el-form :inline="true" ref="dataFormRef" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item label="类型" prop="type">
        <el-select v-model="dataForm.type" placeholder="请选择类型">
          <el-option v-for="item in options" :key="item.code" :label="item.label" :value="item.code">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开始日期时间" prop="start_time">
        <el-date-picker v-model="dataForm.start_time" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择开始日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束日期时间" prop="end_time">
        <el-date-picker v-model="dataForm.end_time" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择结束日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button @click="resetDataForm()">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%">
      <el-table-column prop="push_id" header-align="center" align="center" width="260" label="推送ID">
      </el-table-column>
      <el-table-column prop="push_time" header-align="center" align="center" width="200" label="推送时间">
      </el-table-column>
      <el-table-column prop="desc" header-align="center" align="center" width="200" label="类型">
      </el-table-column>
      <el-table-column prop="data" header-align="center" align="center" label="消息数据">
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dataForm: {
        type: '',
        start_time: '',
        end_time: ''
      },
      options: [
        {
          code: '',
          label: '全部'
        },
        {
          code: 'order.success',
          label: '交易成功'
        },
        {
          code: 'goods.on.sale',
          label: '商品上架'
        },
        {
          code: 'goods.undercarriage',
          label: '商品下架'
        },
        {
          code: 'order.delivered',
          label: '商品已收货'
        },
        {
          code: 'goods.alter',
          label: '商品修改'
        },
        {
          code: 'goods.price.alter',
          label: '商品价格变更'
        },
        {
          code: 'order.delivery',
          label: '商家已发货'
        },
        {
          code: 'afterSale.success',
          label: '售后退款到账'
        },
        {
          code: 'afterSale.agree',
          label: '售后同意'
        },
        {
          code: 'afterSale.refuse',
          label: '售后拒绝'
        },
        {
          code: 'goods.storage.remove',
          label: '移除商品库商品'
        }
      ],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
    }
  },
  created () {
    this.getDataList()
  },
  methods: {
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('admin/third/call/back/log/list'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'key': this.dataForm.key,
          ...this.dataForm
        })
      }).then(({ data }) => {
        if (data && data.code === 200) {
          this.dataList = data.page.list
          this.totalPage = data.page.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    resetDataForm () {
      this.$refs.dataFormRef.resetFields()
      this.pageIndex = 1
      this.getDataList()
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    }
  }
}
</script>

<style lang="scss" scoped>
.container-log {}
</style>